import Vue from 'vue'
import axios from 'axios'

import App from './App'
import router from './router'
import store from './store'
import iView from 'iview'
import 'iview/dist/styles/iview.css'
import electron from 'electron'
import fn from './assets/js/function'
import db from './nedb'
import vuescroll from 'vuescroll'
import 'vuescroll/dist/vuescroll.css'
import VueClickout from '@xunlei/vue-clickout'
import VueSocketio from 'vue-socket.io'
import socketio from 'socket.io-client'
import 'viewerjs/dist/viewer.css'
import Viewer from 'v-viewer'

Vue.use(Viewer)
Vue.use(VueSocketio, socketio(store.state.node_url))
Vue.prototype.$db = db
Vue.prototype.$fn = fn
Vue.prototype.electron = electron

Vue.use(iView)
Vue.use(vuescroll)
Vue.use(VueClickout)
if (!process.env.IS_WEB) Vue.use(require('vue-electron'))
Vue.http = Vue.prototype.$http = axios
Vue.config.productionTip = false

Vue.filter('formatDate', function (value, formType) { // 时间戳格式化
  value = parseInt(value)
  if (value === 0) return ''
  if (!value) return ''
  formType = formType || 'yyyy-MM-dd hh:mm:ss'
  let date = new Date(value.toString().length > 10 ? value : value * 1000)
  return fn.formatDate(date, formType)
})

Vue.filter('formatPicPath', function (value) {
  if (value.indexOf('https://') === -1 && value.indexOf('http://') === -1 && value.indexOf('blob:') === -1) {
    return store.state.sever_web + value
  }
  return value
})

/* eslint-disable no-new */
new Vue({
  components: { App },
  router,
  store,
  template: '<App/>'
}).$mount('#app')
